/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package arimaa;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;

/**
 *
 * @author student
 */
public class Piece {
    // Square currentSquare;
    int x;
    boolean frozen = false;
    int y;
    int rank = -1;
    boolean player;

    boolean selected = false;

    //creating the image setup
    final static String[] pieceNames = {"Rabbit", "Cat", "Dog", "Horse", "Camel", "Elephant"};
    final static BufferedImage goldImages[] = new BufferedImage[6];
    final static BufferedImage silverImages[] = new BufferedImage[6];

    public Piece(int rank, boolean player) {
        this.rank = rank;
        this.player = player;
    }

    static public void loadImages() {
        //loads the piece images
        for (int i = 0; i < pieceNames.length; i++) {
            try {
                goldImages[i] = ImageIO.read(new File("images/Gold" + pieceNames[i] + ".png"));
                silverImages[i] = ImageIO.read(new File("images/Silver" + pieceNames[i] + ".png"));

            } catch (Exception e) {
                System.out.println("failed to load image " + pieceNames[i]);
                e.printStackTrace();
            }
        }
    }

    //draws the image of the piece at the designated location, and highlights the 
    //box if selected == true
    public void paintSelf(Graphics g, int x, int y, int width, int height) {
        if (player == Arimaa.GOLD) {
            g.drawImage(goldImages[rank], x, y, width, height, null);

        } else {
            g.drawImage(silverImages[rank], x, y, width, height, null);
        }
        if (selected){
        g.setColor(Color.green);
        g.drawRect(x, y, width, height);
        }
    }

    public boolean getPlayer() {
        return player;
    }

    public void setPlayer(boolean player) {
        this.player = player;
    }

    public int getRank() {
        return rank;
    }
    // public void setSquare(Square newCurrentSquare){
    //     currentSquare = newCurrentSquare;
    //  }
    //   public Square getSquare(){
    //      return currentSquare;
    // }
    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }
    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
    public boolean isFrozen() {
        return frozen;
    }

    public void setFrozen(boolean frozen) {
        this.frozen = frozen;
    }

}
